cmake_minimum_required(VERSION 3.5)

project(test_gtk_opengl_demo LANGUAGES C)

find_package(PkgConfig)
pkg_check_modules(GTK IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(GLIB IMPORTED_TARGET glib-2.0)
pkg_check_modules(EPOXY IMPORTED_TARGET epoxy)

add_subdirectory(utils)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/myresources.c
    COMMAND glib-compile-resources
    ARGS --target=${CMAKE_CURRENT_BINARY_DIR}/myresources.c --generate-source --sourcedir=${CMAKE_CURRENT_SOURCE_DIR}/resources ${CMAKE_CURRENT_SOURCE_DIR}/resources/my.gresource.xml
#    DEPENDS clean_myresources_c
    COMMENT "Compiling GResources"
    VERBATIM
)

add_executable(${PROJECT_NAME} main.c)

add_custom_target(maybe_clear_resources_c ALL
#        PRE_BUILD
#        COMMAND ${CMAKE_SOURCE_DIR}/cmake/check_update.sh ${CMAKE_CURRENT_SOURCE_DIR}/resources ${CMAKE_CURRENT_BINARY_DIR}/myresources_update_tmp || rm ${CMAKE_CURRENT_BINARY_DIR}/myresources.c
        COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/check_resources_and_rm_c.sh ${CMAKE_CURRENT_SOURCE_DIR}/resources ${CMAKE_CURRENT_BINARY_DIR}/myresources_update_tmp ${CMAKE_CURRENT_BINARY_DIR}/myresources.c
        COMMENT "bobbi: will clear myresources.c??????????"
        )
add_dependencies(${PROJECT_NAME} maybe_clear_resources_c)

target_sources(${PROJECT_NAME} PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}/myresources.c
    )

target_link_libraries(${PROJECT_NAME}
    PRIVATE
    PkgConfig::GTK
    PkgConfig::EPOXY
    -lm
    opengl_helper
    )
